﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;
using System.IO;

namespace Theosoft.Mobile.LibService
{
    public class StorageService
    {
        private static IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication();

        public static string ReadFromFile(string fileName)
        {
            string result = "";
            using (var file = appStorage.OpenFile(fileName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Read))
            {
                using (var reader = new StreamReader(file))
                {
                    result = reader.ReadToEnd();
                }
            }

            return result;
        }

        public static void StoreToFile(string fileName, string content)
        {
            using (var file = appStorage.OpenFile(fileName, System.IO.FileMode.Append, System.IO.FileAccess.Write))
            {
                using (var writer = new StreamWriter(file))
                {
                    writer.Write(content);
                }
            }
        }
    }
}
